package com.hfut.wxy.controller;

import com.hfut.wxy.common.response.Response;
import com.hfut.wxy.entity.mysql.WxyAddress;
import com.hfut.wxy.service.IAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.hfut.wxy.common.response.Response.success;

@Api(tags = "基础信息")
@RestController
public class BaseController {
    @Resource
    private IAddressService addressService;

    

    @ApiOperation("1 查询个人所有地址")
    @GetMapping("/address/{userId}")
    public Response getAddress(@PathVariable Integer userId){
        return success(addressService.getAddress(userId));
    }

    @ApiOperation("2 添加个人地址/修改个人地址")
    @RequestMapping(value = "/address",method = {RequestMethod.POST,RequestMethod.PUT})
    public Response addAndUpdateAddress(@RequestBody WxyAddress address){
        return success(addressService.addAndUpdateAddress(address));
    }

    @ApiOperation("3 删除个人地址")
    @DeleteMapping("/address/delete/{id}")
    public Response deleteAddress(@PathVariable Integer id){
        addressService.deleteAddress(id);
        return success;
    }


    @ApiOperation("4 获取所有快递网点")
    @GetMapping("/address/pick-up")
    public Response getAllPickUpAddress(){
        return success(addressService.getAllPickUpAddress());
    }


    @ApiOperation("5 修改默认地址")
    @PutMapping(value = "/address/default/{userId}")
    public Response updateDefaultAddress(@PathVariable Integer userId,Integer addressId){
        return success(addressService.updateDefaultAddress(userId,addressId));
    }

    @ApiOperation("6 查询所有的学校")
    @GetMapping("/schools")
    public Response schools(){
        return success(addressService.schools());
    }


}
